#include<iostream>
#include<pthread.h>
#include<cstdio>
using namespace std;
pthread_mutex_t mutex;
pthread_cond_t cond;
void* run(void* arg)
{
  pthread_detach(pthread_self());
  cout<<(char*)arg<<"run....."<<endl;
  while(true)
  {
    pthread_cond_wait(&cond,&mutex);//初始条件不满足，等待条件满足
    cout<<"thread"<<pthread_self()<<"runing.."<<endl;
    
  }
}
int main()
{
  pthread_mutex_init(&mutex,NULL);
  pthread_cond_init(&cond,NULL);
  pthread_t t1,t2,t3;
  pthread_create(&t1,NULL,run,(void*)"thread t1");
  pthread_create(&t2,NULL,run,(void*)"thread t2");
  pthread_create(&t3,NULL,run,(void*)"thread t3");
  while(true)
  {
    getchar();
    pthread_cond_signal(&cond);
  }
  pthread_mutex_destroy(&mutex);
  pthread_cond_destroy(&cond);
  return 0;
}
